package com.attilax.zip;

import java.util.List;
import java.util.function.Function;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

 


import com.attilax.Closure2;
import com.attilax.io.dirx;
import com.attilax.io.filex;

public class CompactFileSearcher {
	static final Logger console = LoggerFactory.getLogger(CompactFileSearcher.class);
	public static void main(String[] args) {
		String d = "C:\\0workspace\\0recy";
		
		console.info(d);
		
		Function<String,Object> findFun = (f2) -> {
			console.info(f2);
			System.out.println("-----"+f2);
			return f2;
		};
		new CompactFileSearcher().search(d,"log4j".toLowerCase(),findFun);
		
		// return this;
	}

	private void search(String d, String kw, Function<String,Object> findFun) {
		Function listRarFun = (f2) -> {
			System.out.println(f2);
			return f2;
		};

		
		Function closure = (f) -> {
			System.out.println(f);
			String zipfile = (String) f;
			String ex = filex.getExtNameV2(zipfile);
			if (ex.trim().toLowerCase().equals("zip")) {
				List<String> li = ZipX.list_resumeMode(zipfile);
				exeFrmFilesWhereFilenameContainKw(kw, findFun, li,zipfile);
			}
			if (ex.trim().toLowerCase().equals("rar"))
			{
				List<String> li2 =RarX.list_resumeMode(zipfile );
				exeFrmFilesWhereFilenameContainKw(kw, findFun, li2,zipfile);
			}
			return f;
		};
		dirx.traveV3(d, closure);
	}

	private void exeFrmFilesWhereFilenameContainKw(String kw, Function<String, Object> findFun, List<String> li, String zipfile) {
		for (String fl : li) {
			if(fl.trim().toLowerCase().contains(kw))
				findFun.apply(zipfile+"/"+fl);
		}
	}

}
